/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO.Comentario;


import DAO.Usuario.HibernateUtil;
import Model.Comentarios;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.hibernate.Session;

/**
 *
 * @author pedro
 */
@Path("/comentarioSave")
public class ComentarioDao {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public Response saveComment(Comentarios comment) {

        Session session = null;
        String resultado = null;
        try{
        session= HibernateUtil.getSession();   
        HibernateUtil.beginTransaction(); 
        session.save(comment);
        HibernateUtil.commitTransaction();  
        resultado = "OK";
        }
       catch (Exception e) {
            System.out.println(e);
            resultado = "Error";
            session.getTransaction().rollback();
       }
        finally {
            try {
                HibernateUtil.closeSession();
            } catch (Throwable e) {
                System.out.println(e.getMessage());
            }
        }
        return Response.status(201).entity(resultado).build();

    }
}
